﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using CodeStandardAddin.Control;

namespace CodeStandardAddin.View.Document
{
	public class ResourceSyntaxModeProvider : ISyntaxModeFileProvider
	{
		List<SyntaxMode> syntaxModes = null;
		
		public ICollection<SyntaxMode> SyntaxModes {
			get {
				return syntaxModes;
			}
		}
		
		public ResourceSyntaxModeProvider()
		{
			Stream syntaxModeStream = CommonUtils.ReadResourceStream(Properties.Resources.SyntaxModes);
			if (syntaxModeStream != null) {
				syntaxModes = SyntaxMode.GetSyntaxModes(syntaxModeStream);
			} else {
				syntaxModes = new List<SyntaxMode>();
			}
		}
		
		public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
		{
			Stream syntaxStream = null;
			switch (syntaxMode.FileName)
			{
				case "CSharp-Mode.xshd":
					syntaxStream = CommonUtils.ReadResourceStream(Properties.Resources.CSharp_Mode);
					break;
				
				case "VBNET-Mode.xshd":
					syntaxStream = CommonUtils.ReadResourceStream(Properties.Resources.VBNET_Mode);
					break;
			}
			return new XmlTextReader(syntaxStream);
		}
		
		public void UpdateSyntaxModeList()
		{
			// resources don't change during runtime
		}
	}
}
